package cn.zj.game.config.type;

/**
 * 数据类型定义
 * @author xi.yang
 * @create 2022-04-12 12:17
 **/
public enum FieldTypeDefine {
    INT("int", "i", int.class,"number"),
    LONG("long", "l", long.class,"number"),
    DOUBLE("double", "d", double.class,"number"),
    STRING("string", "s", String.class,"string"),
    BOOLEAN("boolean", "b", boolean.class,"boolean"),
    CLASS("#Class", "#C", Class.class,""),
    ENUM("#Enum", "#E", Enum.class,""),
    ;
    /**
     * 类型标记
     */
    private String tag;
    /**
     * 简写
     */
    private String code;
    /**
     * 数据类型
     */
    private Class clazz;
    /**
     * ts中的类型名
     */
    private String tsType;

    /**
     * 根据标记获取类型
     * 默认为string类型
     * @param tag
     * @return
     */
    public static FieldTypeDefine findByTag(String tag){
        if (tag.startsWith("#Class")) {
            return FieldTypeDefine.CLASS;
        }
        if (tag.startsWith("#Enum")) {
            return FieldTypeDefine.ENUM;
        }
        tag = tag.replace(" ", "");
        for (FieldTypeDefine value : FieldTypeDefine.values()) {
            if (value.getTag().equalsIgnoreCase(tag) || value.getCode().equalsIgnoreCase(tag)) {
                return value;
            }
        }
        return STRING;
    }

    FieldTypeDefine(String tag, String code, Class clazz, String tsType) {
        this.tag = tag;
        this.code = code;
        this.clazz = clazz;
        this.tsType = tsType;
    }

    public String getTag() {
        return tag;
    }

    public String getTsType() {
        return tsType;
    }

    public String getCode() {
        return code;
    }

    public Class getClazz() {
        return clazz;
    }
}
